package main

import (
	"context"
	"encoding/json"
	"time"
)

type Response struct {
	Date  int64  `json:"date"`
	Error string `json:"error"`
}

func main() {
	es := EsConfig{
		Url:      "http://192.168.2.199:9200",
		Sniff:    false,
		Username: "elastic",
		Password: "123456",
	}

	es.Init()
	m := map[string]interface{}{
		"date":  time.Now().UnixMilli(),
		"error": "测试错误3玩儿",
	}
	data, err := json.Marshal(m)
	if err != nil {
		panic(err)
	}
	_, err = Client.Index().Index("test-20227").Index("test-20227").Id("Z7g-zYEBxze4IQVrv0XH").BodyJson(string(data)).Do(context.Background())
	if err != nil {
		panic(err)
	}

	//result, err :=  Client.Get().Index("test-20227").Id("Z7g-zYEBxze4IQVrv0XH").Do(context.Background())
	//if err != nil {
	// panic(err)
	//}
	//fmt.Printf("%s",result.Source.UnmarshalJSON())
	//query := elastic.NewMatchAllQuery()
	//data, _, _ := Search("test-20227", query)
	//
	//for _, datum := range data {
	//	var res *Response
	//	err := json.Unmarshal(datum, &res)
	//	if err != nil {
	//		panic(err)
	//	}
	//	fmt.Println(res.Error)
	//}

}
